//
//  IncomeDynamicTableViewController.swift
//  HuaYun
//
//  Created by enghou on 2018/12/14.
//  Copyright © 2018 xyxorigation. All rights reserved.
//

import UIKit

class IncomeDynamicTableViewController: BaseSectionedTableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return source[section].count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        return tableView.dequeueReusableCell(withIdentifier: "ApprovalDetailCell")!
    }
    override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        if let cel = cell as? ApprovalDetailCell {
            cel.selectionStyle = .none
            if source.count > indexPath.section {
                if source[indexPath.section].count > indexPath.row {
                    let model = source[indexPath.section][indexPath.row]
                    cel.title = model.keys.first ?? ""
                    cel.content = model[model.keys.first!] ?? ""
                }
            }
        }
    }
    
    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if source.count > indexPath.section {
            let array = source[indexPath.section]
            if array.count > indexPath.row {
                if indexPath.row > 0 {
                    let model = source[indexPath.section][indexPath.row]
                    if let key = model.keys.first {
                        if let string = model[key] as? String {
                            if string.count > 0 {
                                let size = string.size(with: UIFont.systemFont(ofSize: 15), maxSize: CGSize.init(width: tableView.width - 40, height: 1000000))
                                return 55 + size.height
                            }
                            return 65
                        }
                    }
                }
            }
        }
        return 65
    }

}
